/-boot
/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
/-shell
/-storage ...
/-storage/attached ...
/-storage/attached/api
/-storage/attached/dom
/-storage/attached/indexedDB ...
DetectStorage.ts
FileData.ts
LoadStorage.ts
MetadataData.ts
StorageAccess.ts
StorageDetect.ts
UpdateStorage.ts
functions.ts
/-storage/attached/localStorage
/-storage/attached/webSQL
/-tests
/-tests/files
/-tests/storage
/-tests/storage/attached
AttachedStorageTests.ts
AttachedStorageTestsNew.ts
DomStorageTests.ts
IndexedDBStorageTests.ts
LocalStorageStorageTests.ts
WebSQLStorageTests.ts
TestCase.html
TestCase.ts
TestPage.css
TestPage.html
TestPage.ts
_sampleTests.ts
teapo-tests.html
teapo-tests.ts
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
try.html
try.js
xxxxxxxxxx
 
1
module teapo.storage.attached.indexedDB {
2
​
3
  export class StorageAccess implements attached.StorageAccess {
4
​
5
    constructor(private _db: IDBDatabase) {
6
    }
7
​
8
    update(
9
      byFullPath: PropertiesByFullPath,
10
      timestamp: number,
11
      callback: (error: Error) => void): void {
12
​
13
      var transaction = this._db.transaction(['files', 'metadata'], 'readwrite');
14
      transaction.onerror = (errorEvent) => callback(wrapErrorEvent(errorEvent, 'update: transaction'));
15
      var filesStore = transaction.objectStore('files');
16
      
17
      var outstandingRequests = 1;
18
​
19
      function oneError(errorEvent: ErrorEvent, moreDescription) {
20
        if (!outstandingRequests) return;
21
​
22
        outstandingRequests = 0;
23
        callback(wrapErrorEvent(errorEvent, moreDescription));
24
      }
25
​
26
      function oneCompleted() {
27
        if (!outstandingRequests) return;
28
​
29
        outstandingRequests--;
30
        if (!outstandingRequests)
31
          callback(null);
32
      }
33
​
34
      for (var fullPath in byFullPath) if (byFullPath.hasOwnProperty(fullPath)) {
35
​
36
        var pbag = byFullPath[fullPath];
37
​
38
        if (!pbag) {
39
          var deleteRequest = filesStore['delete'](fullPath);
40
          outstandingRequests++;
41
​
42
          deleteRequest.onerror = (errorEvent) => oneError(errorEvent, 'update: objectStore(files).delete(' + fullPath+')');
43
          deleteRequest.onsuccess = (event) => {
44
            oneCompleted();
45
          };
46
        }
47
        else {
48
          var getRequest = filesStore.get(fullPath);
49
          outstandingRequests++;
50
​
51
          getRequest.onerror = (errorEvent) => oneError(errorEvent, 'update: objectStore(files).delete(' + fullPath + ')');
52
          getRequest.onsuccess = (event) => {
53
​
54
            var fileData: FileData = getRequest.result || { path: fullPath, properties: {} };
55
​
56
            var properties = fileData.properties || (fileData.properties = {});
57
            for (var p in pbag) if (pbag.hasOwnProperty(p)) {
58
              var v = pbag[p];
59
              if (v === null || typeof v === 'undefined')
60
                delete properties[p];
61
              else
62
                properties[p] = v;
63
            }
64
​
65
            var putFile = filesStore.put(fileData);
66
            getRequest.onerror = (errorEvent) => oneError(errorEvent, 'update: objectStore(files).put(' + fullPath + ')');
67
            putFile.onsuccess = (event) =>
68
              this._updateEditedUTC(
69
                timestamp,
70
                transaction,
71
                (errorEvent) => {
72
                  if (errorEvent)
73
                    oneError(errorEvent, 'update: _updateEditedUTC');
74
                  else
75
                    oneCompleted();
76
                });
77
          };
78
        }
79
        
80
      }
81
​
82
      oneCompleted();
83
    }
84
​
85
    read(
86
      fullPath: string,
87
      callback: (error: Error, properties: { [property: string]: string; }) => void): void {
30:10 function (error: Error): void